package com.token.sysflow.bean;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import com.token.sql.IntegrateSql;
import com.token.sql.AbstractTableBean;
/**
 * 授权应用
 * @author 代码创建
 */
public class FSysAuthorizedApp extends AbstractTableBean {

    private long AuthId; //关联Id
    private String AppKeyId; //应用KeyId

    public FSysAuthorizedApp (IntegrateSql f){
        super(f,"F_Sys_AuthorizedApp");
        this.setKeyName("AuthAppId");
    }

    public FSysAuthorizedApp (IntegrateSql f,ResultSet rs) throws SQLException{
        super(f,"F_Sys_AuthorizedApp");
        this.setKeyName("AuthAppId");
        this.initParamToRs(rs);
    }

    public FSysAuthorizedApp (IntegrateSql f,String keyValue) throws SQLException{
        super(f,"F_Sys_AuthorizedApp");
        this.setKeyName("AuthAppId");
        setCodePrepare(selectCodeById().toString());
        prepareSql.setPstValue(1, keyValue);
        ResultSet rs = executeQuery();
        if(rs.next()){
            initParamToRs(rs);
        }else{
            initParam();
        }
        rs.close();
    }

    @Override
    protected void initParam() {
        AuthId = 0; //关联Id
        AppKeyId = ""; //应用KeyId
    }


    public void initParamToRs(ResultSet rs) throws SQLException{
        AuthId = rs.getLong("AuthId"); //关联Id
        AppKeyId = rs.getString("AppKeyId"); //应用KeyId
        this.setKeyId(rs.getString("AuthAppId"));
    }


    @Override
    protected int appendData() throws SQLException {
        int i = 1;
        prepareSql.setPstValue(i++,AuthId); //关联Id
        prepareSql.setPstValue(i++,AppKeyId); //应用KeyId
        return i;
    }


    @Override
    public Vector<String> getFields() {
        Vector<String> vec = new Vector<String>();
        vec.addElement("AuthId"); //关联Id
        vec.addElement("AppKeyId"); //应用KeyId
        return vec;
    }


    /**
     * 设置关联Id
     * @param authid
     */
    public void setAuthId(long authid){
        AuthId = authid;
    }
    /**
     * 获取AuthId
     * @return 关联Id
     */
    public long getAuthId(){
        return AuthId;
    }

    /**
     * 设置应用KeyId
     * @param appkeyid
     */
    public void setAppKeyId(String appkeyid){
        AppKeyId = appkeyid;
    }
    /**
     * 获取AppKeyId
     * @return 应用KeyId
     */
    public String getAppKeyId(){
        return AppKeyId;
    }

}
